﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ShevaEngine.Core.Foundation
{
    /// <summary>
    /// Pair class.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <typeparam name="U"></typeparam>
    public class Pair<T,U>
    {
        /// <summary>First.</summary>
        public T First { get; set; }
        /// <summary>Second.</summary>
        public U Second { get; set; }

        /// <summary>
        /// Konstruktor.
        /// </summary>
        public Pair()
        {
        }

        /// <summary>
        /// Konstruktor.
        /// </summary>
        /// <param name="first"></param>
        /// <param name="second"></param>
        public Pair(T first, U second)
        {
            this.First = first;
            this.Second = second;
        }        
    }

    /// <summary>
    /// Pair comparer.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <typeparam name="U"></typeparam>
    public class PairComparer<T, U> : IComparer<Pair<T, U>>
    {
        /// <summary>
        /// Method compares Pair{T, U}./>
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public int Compare(Pair<T, U> x, Pair<T, U> y)
        {
            int comp = Comparer<T>.Default.Compare(x.First, y.First);

            if (comp == 0)
                return Comparer<U>.Default.Compare(x.Second, y.Second);

            return comp;
        }
    }
}
